package org.abc.fund.repository.funds;

import org.abc.fund.entity.funds.FundDividend;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.util.Optional;

/**
 * Repository for FundDividend entity.
 */
@Repository
public interface FundDividendRepository extends JpaRepository<FundDividend, Long> {
    /**
     * 根据基金代码和公告日期查找分红记录
     */
    Optional<FundDividend> findByFundCodeAndPubDate(String fundCode, LocalDate pubDate);
    
    /**
     * 根据基金代码查找最新的分红记录（按公告日期降序）
     */
    Optional<FundDividend> findTopByFundCodeOrderByPubDateDesc(String fundCode);

    @Modifying
    @Transactional
    void deleteByFundCodeAndPubDateBetween(String fundCode, LocalDate startDate, LocalDate endDate);
}

